<html xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers" data-namespace-typo3-fluid="true">
<link rel="stylesheet" type="text/css" href="{f:uri.resource(path:'Css/style.css')}" />
<script type="text/javascript" src="{f:uri.resource(path:'JavaScript/jquery.validate.min.js')}"></script>
<script type="text/javascript" src="{f:uri.resource(path:'JavaScript/messages_zh.js')}"></script>

<div class="form-group">
	<label class="control-label" >
		用户名（或手机号）<font color="red">*</font>
	</label>
	<f:form.textfield property="username" id="susername" class="form-control" />
</div>
<div class="form-group">
	<label class="control-label" >
		用户姓名<font color="red">*</font>
	</label>
	<f:form.textfield property="name" class="form-control" />
</div>
<div class="form-group">
	<label class="control-label" >
		用户性别<font color="red">*</font>
	</label><br/>
	<f:if condition="!{user}">
		<f:then>
			<f:for each="{sexs}" as="sex" iteration="num">
				<f:form.radio property="gender" value="{sex.label}" checked="{f:if(condition:'{num.index}==0',then:'checked')}" />{sex.name}
			</f:for>
		</f:then>
		<f:else>
			<f:for each="{sexs}" as="sex">
				<f:form.radio property="gender" value="{sex.label}" />{sex.name}
			</f:for>
		</f:else>
	</f:if>
</div>
<div class="form-group">
	<label class="control-label" >
		用户手机号<font color="red">*</font>
	</label>
	<f:form.textfield property="telephone" class="form-control" />
</div>
<div class="form-group">
	<label class="control-label" >
		用邮箱<font color="red">*</font>
	</label>
	<f:form.textfield property="email" id="semail" class="form-control" />
</div>
<div class="form-group">
	<label class="control-label" >
		所在学校<font color="red">*</font>
	</label>
	<f:form.textfield property="company" class="form-control" />
</div>
<div class="form-group">
	<label class="control-label" >
		用户角色<font color="red">*</font>
	</label>
	<f:form.select class="input-sm form-control" value="{user.usergroup}"  name="usergroup" options="{groups}" optionValueField="uid" optionLabelField="title"  />  
</div>
<f:if condition="!{user}">
	<f:then>
		<div class="form-group">
			<label class="control-label" >
				用户密码<font color="red">*</font>
			</label><br/>
			默认密码为123456
		</div>
		<f:form.hidden name="suid" id="suid" value="0"/>
	</f:then>
	<f:else>
		<f:form.hidden name="suid" id="suid" value="{user.uid}"/>
	</f:else>
</f:if>
<script type="text/javascript">
	$(function(){
		$("#NewEditUserValid").validate({
			errorElement: "span", 
			rules: {
				'tx_user_user[user][username]': {
					required: true ,
					remote:{
			            url: "<f:uri.action action='checkus'  />",
			            type: 'post',
			            dataType: 'json',
				        data: {
				        	'susername': function(){
				            	return $("#susername").val();
				            },
				            'suid': function(){
				            	return $("#suid").val();
				            }
			            }
				    } 
				},
				'tx_user_user[user][name]': {
					required: true,
				},
				 'tx_user_user[user][gender]': {
					required: true,
				　},
				 'tx_user_user[user][telephone]': {
					required: true,
					isTelphone:true
				　},
				'tx_user_user[user][email]': {
					required: true,
					email:true,
					remote:{
			            url: "<f:uri.action action='checkus'  />",
			            type: 'post',
			            dataType: 'json',
				        data: {
				        	'semail': function(){
				            	return $("#semail").val();
				            },
				            'suid': function(){
				            	return $("#suid").val();
				            }
			            }
				    }
			　　},
			  'tx_user_user[user][company]': {
					required: true,
			　　}
			},
			messages: {
				'tx_user_user[user][username]': {
					required: "请输入用户名!",
					remote:"用户名已存在！"
				},
				'tx_user_user[user][name]': {
					required: "请输入用户姓名！",
				},
				'tx_user_user[user][gender]': {
					required: "请选择用户性别！",
				},
				'tx_user_user[user][telephone]': {
					required: "请输入用户电话！",
					isTelphone:"手机号输入错误！"
				},
				'tx_user_user[user][email]': {
					required: "请输入邮箱地址，方便找回密码使用!",
					email:"输入正确格式的邮箱！",
					remote:"邮箱已经存在！" 
				},
				'tx_user_user[user][company]': {
					required: "请输入所在学校！",
				}
			}   
	    });
		jQuery.validator.addMethod("isTelphone", function(value, element) { 
		    var tel = /^1[3|4|5|6|7|8|9][0-9]\d{8}$/;
		    return this.optional(element) || (tel.test(value));
		}, "手机号输入错误");
	});
</script>
</html>